package com.noble.glamour.ui.user.my.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.noble.glamour.R;
import com.noble.glamour.bean.my.RedbagList;
import com.noble.glamour.module.logic.baseui.ExBaseAdapter;
import com.noble.glamour.ui.user.my.wallet.TreeRedBagRecordPanel;


/**
 * 红包列表
 * Created by zm on 2017/4/13.
 */
public class TreeRedBagTabAdapter extends ExBaseAdapter<RedbagList.RedbagInfo>{

    public TreeRedBagTabAdapter(Context context, TreeRedBagRecordPanel treeRedBagRecordPanel){
        super(context, null);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final MyViewHolder vh;
        if (convertView == null) {
            convertView = inflate(R.layout.f1_wode_withdraw_item);
            vh = new MyViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (MyViewHolder) convertView.getTag();
        }

        final RedbagList.RedbagInfo info = getItem(position);
        String time = info.getCreate_time();//获取获得红包的时间
        if (!TextUtils.isEmpty(time)) {
            String[] tempArr = time.split(" ");
            vh.tvData.setText(tempArr[0].replace("-", ".") + "\n" + tempArr[1].substring(0, 5));
        }
        //路径 服务器新增字段：type_text
        //红包类型 1 水果游戏红包(旧) 2 打擂奖励/排行奖励 3 聊天红包 4 聊天排名奖励(旧) 5 礼物折现 6. 摇钱树红包 7.8 好友邀请 9.视频聊天 10.语音聊天
        // 11.视频任务补贴 12.语音任务补贴 13.礼物任务补贴 14.活跃奖金
        vh.tvPath.setText(info.getType_text());
        vh.tvMoney.setText(info.getMoney()+"");
        //操作
        if (info.getFrozen() == 2) {
            vh.tvStatus.setText("已解冻");
            vh.tvStatus.setTextColor(Color.parseColor("#fd698c"));
        } else {
            vh.tvStatus.setText("冻结");
            vh.tvStatus.setTextColor(Color.parseColor("#9fa0a0"));
        }
        return convertView;
    }

    class MyViewHolder {
        TextView tvData,tvPath,tvMoney,tvStatus;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            tvData = (TextView) convertView.findViewById(R.id.withdraw_tv_date);
            tvPath = (TextView) convertView.findViewById(R.id.withdraw_tv_path);
            tvMoney = (TextView) convertView.findViewById(R.id.withdraw_tv_money);
            tvStatus = (TextView) convertView.findViewById(R.id.withdraw_tv_status);
        }
    }
}